using UnityEngine;
using System.Collections;

public class GUIEnding : MonoBehaviour {


	public Texture fleche;
	private string m_ID = "";
	private int m_selection = 0;

	void OnGUI()
	{
		GUI.Box(new Rect(Screen.width * 0.5f - 150, Screen.height * 0.5f - 100, 300, 200), "");
		GUILayout.BeginArea(new Rect(Screen.width * 0.5f - 150, Screen.height * 0.5f - 100, 300, 200));

		GUILayout.BeginVertical();


		GUILayout.TextArea("Score :" + player.m_Score +"\nWrite your name and upload it if you want.", 100);

		GUILayout.TextField(this.m_ID);

		GUILayout.TextArea("Upload", 100);
		GUILayout.TextArea("Restart", 100);
		GUILayout.TextArea("Menu", 100);

		GUILayout.EndVertical();

		GUILayout.EndArea();

		if (m_selection == 0)
		{
			GUI.DrawTexture(new Rect(Screen.width * 0.5f - 170, Screen.height * 0.5f - 35, 20, 20), fleche, ScaleMode.ScaleAndCrop, false, 1);
		}
		else if (m_selection == 1)
		{
			GUI.DrawTexture(new Rect(Screen.width * 0.5f - 170, Screen.height * 0.5f - 10, 20, 20), fleche, ScaleMode.ScaleAndCrop, false, 1);
		}
		else if (m_selection == 2)
		{
			GUI.DrawTexture(new Rect(Screen.width * 0.5f - 170, Screen.height * 0.5f + 15, 20, 20), fleche, ScaleMode.ScaleAndCrop, false, 1);
		}
	}

	void Update()
	{
		if (Input.GetKeyDown("down") && m_selection < 2)
		{
			m_selection++;
		}

		if (Input.GetKeyDown("up") && m_selection > 0)
		{
			m_selection--;
		}

		if (Input.GetKeyDown("return") && m_selection == 0)
		{
			//uploading leaderboard + page leaderboard
			HSController.sScore = player.m_Score;
			HSController.sPostScore = true;
			Application.LoadLevel(2);
		}
		else if (Input.GetKeyDown("return") && m_selection == 1)
		{
			//restart
			Application.LoadLevel(1);
		}
		else if (Input.GetKeyDown("return") && m_selection == 2)
		{
			//menu
			Application.LoadLevel(0);
		}
	}
}
